﻿
// <copyright file="InverseComparer.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The inverse comparer.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System.Collections.Generic;

    /// <summary>
    /// The inverse comparer.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class InverseComparer<T> : IComparer<T>
    {
        #region Fields

        /// <summary>
        /// The adaptedObject.
        /// </summary>
        private readonly IComparer<T> adaptedObject;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="InverseComparer{T}"/> class.
        /// </summary>
        /// <param name="adaptedObject">
        /// The adaptedObject.
        /// </param>
        public InverseComparer(IComparer<T> adaptedObject)
        {
            this.adaptedObject = adaptedObject;
        }

        #endregion Constructors and Finalizers

        #region Public Methods and Operators

        /// <summary>
        /// The compare.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Compare(T x, T y)
        {
            return -this.adaptedObject.Compare(x, y);
        }

        #endregion Public Methods and Operators
    }
}